package org.lex.swing.plaf.widget;

import javax.swing.DefaultListModel;
import javax.swing.JList;
import javax.swing.ListSelectionModel;
import javax.swing.plaf.metal.MetalTheme;

import org.lex.swing.plaf.util.LookAndFeelUtils;

public class ThemeList extends JList {
	private DefaultListModel model = null;

	public ThemeList() {
		model = new DefaultListModel();
		for (MetalTheme mt : LookAndFeelUtils.getMetalThemes()) {
			model.addElement(mt);
		}
		this.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
		this.setModel(model);
	}

	public MetalTheme getSelectedTheme() {
		int index = this.getSelectedIndex();
		if (-1 == index) {
			return null;
		} else {
			return (MetalTheme) model.getElementAt(index);
		}
	}
}
